package com.android;

import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class GameBoard extends Activity implements OnClickListener {
	//stores the passed time from the counter
	Integer time=0;
	//stops the time when the game is finished
	Integer timeFinished = 0;
	//lists for id and card
	List<Integer> id = new ArrayList<Integer>();
    List<Integer> card = new ArrayList<Integer>();
	//create the player
	public Player player = new Player();
	//Create the highscorelist
	public HighScoreData hsdata = new HighScoreData();
	//create all the 24 cards
	public CreateCards card1 = new CreateCards();
	public CreateCards card2 = new CreateCards();
	public CreateCards card3 = new CreateCards();
	public CreateCards card4 = new CreateCards();
	public CreateCards card5 = new CreateCards();
	public CreateCards card6 = new CreateCards();
	public CreateCards card7 = new CreateCards();
	public CreateCards card8 = new CreateCards();
	public CreateCards card9 = new CreateCards();
	public CreateCards card10 = new CreateCards();
	public CreateCards card11 = new CreateCards();
	public CreateCards card12 = new CreateCards();
	public CreateCards card13 = new CreateCards();
	public CreateCards card14 = new CreateCards();
	public CreateCards card15 = new CreateCards();
	public CreateCards card16 = new CreateCards();
	public CreateCards card17 = new CreateCards();
	public CreateCards card18 = new CreateCards();
	public CreateCards card19 = new CreateCards();
	public CreateCards card20 = new CreateCards();
	public CreateCards card21 = new CreateCards();
	public CreateCards card22 = new CreateCards();
	public CreateCards card23 = new CreateCards();
	public CreateCards card24 = new CreateCards();
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gameboard);
        
        //back button
        Button back = (Button) findViewById(R.id.back);
        back.setOnClickListener(this);
        //submit button
        Button submit = (Button) findViewById(R.id.submit);
        submit.setOnClickListener(this);
        //turncards button
        Button turncards = (Button) findViewById(R.id.turncards);
        turncards.setOnClickListener(this);
        //adding the image to the 24 cards.
        
        //start a 10minute counter
        new CountDownTimer(600000, 1000) {

        	//update the time on ticks.
            public void onTick(long millisUntilFinished) {
            	TextView tid=(TextView)findViewById(R.id.timer);
            	if(timeFinished == 0){
            		time=time+1;
                	tid.setText("Timer: " + time + " Seconds.");
            	}
            }
            
            //after 10min the game closes.
            public void onFinish() {
            	TextView tid=(TextView)findViewById(R.id.timer);
                tid.setText("10minutes has passed! No more time.");
                gameOver();
            }
       }.start();
       
        assignImageListener();
        setCardIds();
        setAllCardsUnfinished();
        randomizeCards();
    }
	
	public void gameOver(){
		// prepare the alert box
        AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

        // set the text message
        alertbox.setMessage("10 minutes have passed and the time is over. Restart game?");

        // add a neutral button to the alert box and assign a click listener
        alertbox.setCancelable(false)
        //if the player presses yes do this
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
            	 //close the activity
            	GameBoard.this.finish();
        		Intent intent  = new Intent(getBaseContext(), GameBoard.class);
        		startActivity(intent);
            }
        })
        //if the player presses no do this
        .setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
            	//go to mainmenu
            	GameBoard.this.finish();
        		Intent intent  = new Intent(getBaseContext(), MemoryActivity.class);
        		startActivity(intent);
            }
        });
        // show it
        alertbox.show();
	}
	
	public void assignImageListener(){
		//give all the cards a clickListener
		ImageView image1 = (ImageView) findViewById(R.id.card1);
	    image1.setOnClickListener(this);
	    ImageView image2 = (ImageView) findViewById(R.id.card2);
	    image2.setOnClickListener(this);
	    ImageView image3 = (ImageView) findViewById(R.id.card3);
	    image3.setOnClickListener(this);
	    ImageView image4 = (ImageView) findViewById(R.id.card4);
	    image4.setOnClickListener(this);
	    ImageView image5 = (ImageView) findViewById(R.id.card5);
	    image5.setOnClickListener(this);
	    ImageView image6 = (ImageView) findViewById(R.id.card6);
	    image6.setOnClickListener(this);
	    ImageView image7 = (ImageView) findViewById(R.id.card7);
	    image7.setOnClickListener(this);
	    ImageView image8 = (ImageView) findViewById(R.id.card8);
	    image8.setOnClickListener(this);
	    ImageView image9 = (ImageView) findViewById(R.id.card9);
	    image9.setOnClickListener(this);
	    ImageView image10 = (ImageView) findViewById(R.id.card10);
	    image10.setOnClickListener(this);
	    ImageView image11 = (ImageView) findViewById(R.id.card11);
	    image11.setOnClickListener(this);
	    ImageView image12 = (ImageView) findViewById(R.id.card12);
	    image12.setOnClickListener(this);
	    ImageView image13 = (ImageView) findViewById(R.id.card13);
	    image13.setOnClickListener(this);
	    ImageView image14 = (ImageView) findViewById(R.id.card14);
	    image14.setOnClickListener(this);
	    ImageView image15 = (ImageView) findViewById(R.id.card15);
	    image15.setOnClickListener(this);
	    ImageView image16 = (ImageView) findViewById(R.id.card16);
	    image16.setOnClickListener(this);
	    ImageView image17 = (ImageView) findViewById(R.id.card17);
	    image17.setOnClickListener(this);
	    ImageView image18 = (ImageView) findViewById(R.id.card18);
	    image18.setOnClickListener(this);
	    ImageView image19 = (ImageView) findViewById(R.id.card19);
	    image19.setOnClickListener(this);
	    ImageView image20 = (ImageView) findViewById(R.id.card20);
	    image20.setOnClickListener(this);
	    ImageView image21 = (ImageView) findViewById(R.id.card21);
	    image21.setOnClickListener(this);
	    ImageView image22 = (ImageView) findViewById(R.id.card22);
	    image22.setOnClickListener(this);
	    ImageView image23 = (ImageView) findViewById(R.id.card23);
	    image23.setOnClickListener(this);
	    ImageView image24 = (ImageView) findViewById(R.id.card24);
	    image24.setOnClickListener(this);
	}
	
	public void setCardIds(){
		//set a id to the different pairs, 12 pairs therefore there are 12ids
        
        card.add(0);//this is to set the first slot in the array, this is unused.
        id.add(0);  //this is to set the first slot in the array, this is unused.
        id.add(1);
        card.add(R.drawable.card1);
        id.add(1);
        card.add(R.drawable.card1);
        id.add(2);
        card.add(R.drawable.card2);
        id.add(2);
        card.add(R.drawable.card2);
        id.add(3);
        card.add(R.drawable.card3);
        id.add(3);
        card.add(R.drawable.card3);
        id.add(4);
        card.add(R.drawable.card4);
        id.add(4);
        card.add(R.drawable.card4);
        id.add(5);
        card.add(R.drawable.card5);
        id.add(5);
        card.add(R.drawable.card5);
        id.add(6);
        card.add(R.drawable.card6);
        id.add(6);
        card.add(R.drawable.card6);
        id.add(7);
        card.add(R.drawable.card7);
        id.add(7);
        card.add(R.drawable.card7);
        id.add(8);
        card.add(R.drawable.card8);
        id.add(8);
        card.add(R.drawable.card8);
        id.add(9);
        card.add(R.drawable.card9);
        id.add(9);
        card.add(R.drawable.card9);
        id.add(10);
        card.add(R.drawable.card10);
        id.add(10);
        card.add(R.drawable.card10);
        id.add(11);
        card.add(R.drawable.card11);
        id.add(11);
        card.add(R.drawable.card11);
        id.add(12);
        card.add(R.drawable.card12);
        id.add(12);
        card.add(R.drawable.card12);
	}
	
	public void setAllCardsUnfinished(){
		//set all cards as unfinished
        for(int i=1;i<25;i++){
        	player.setCardFinished(i, false);
        }
	}

	public void randomizeCards(){
		//give all the cards a random picture
		Random randInt = new Random();
        int b=0;
        	
        	//this loop makes sure a new unique picture is assigned
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
        	}
        	//set the new randomized imagename
        	card1.setImageName(card.get(b));
        	//asign the imagetype id to the real ID
        	player.setRealCardId(1, id.get(b));
        	//set it so the current picture chosen becomes 0 and cant be picked again.
        	card.set(b, 0);
            
        	//This repeats for the other cards below:
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card2.setImageName(card.get(b));
        	player.setRealCardId(2, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card3.setImageName(card.get(b));
        	player.setRealCardId(3, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card4.setImageName(card.get(b));
        	player.setRealCardId(4, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card5.setImageName(card.get(b));
        	player.setRealCardId(5, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card6.setImageName(card.get(b));
        	player.setRealCardId(6, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card7.setImageName(card.get(b));
        	player.setRealCardId(7, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card8.setImageName(card.get(b));
        	player.setRealCardId(8, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card9.setImageName(card.get(b));
        	player.setRealCardId(9, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card10.setImageName(card.get(b));
        	player.setRealCardId(10, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card11.setImageName(card.get(b));
        	player.setRealCardId(11, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card12.setImageName(card.get(b));
        	player.setRealCardId(12, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card13.setImageName(card.get(b));
        	player.setRealCardId(13, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card14.setImageName(card.get(b));
        	player.setRealCardId(14, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card15.setImageName(card.get(b));
        	player.setRealCardId(15, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card16.setImageName(card.get(b));
        	player.setRealCardId(16, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card17.setImageName(card.get(b));
        	player.setRealCardId(17, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card18.setImageName(card.get(b));
        	player.setRealCardId(18, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card19.setImageName(card.get(b));
        	player.setRealCardId(19, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card20.setImageName(card.get(b));
        	player.setRealCardId(20, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card21.setImageName(card.get(b));
        	player.setRealCardId(21, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card22.setImageName(card.get(b));
        	player.setRealCardId(22, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card23.setImageName(card.get(b));
        	player.setRealCardId(23, id.get(b));
        	card.set(b, 0);
            
        	while(card.get(b) == 0){
        		b = randInt.nextInt(24)+1;
            }
        	card24.setImageName(card.get(b));
        	player.setRealCardId(24, id.get(b));
        	card.set(b, 0);
        //for(int i=1; i<25;i++){
       // CreateCards card = new CreateCards();
        //card.setId(1);
       // card.setImageName("card1");
        //}
	}
	
	@Override
	public void onClick(View v) {
		if(v == findViewById(R.id.submit)){
			//close current activity
			this.finish();
			Intent intent  = new Intent(getBaseContext(), Submit.class);
			//send 2 variables from this class to the HighScore class
			Bundle b = new Bundle();
			b.putInt("value", hsdata.getTurns());
			b.putInt("valuex", time);
			//add the 2 integers to the intent
			intent.putExtras(b);
			
			//open the highscore window
    		startActivity(intent);
		}else if(v == findViewById(R.id.back)){
			
			// prepare the alert box
            AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
 
            // set the text message
            alertbox.setMessage("Do you want to go back and end the current game?");
 
            // add a neutral button to the alert box and assign a click listener
            alertbox.setCancelable(false)
            //if the player presses yes do this
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                	 //close the activity
                	GameBoard.this.finish();
            		Intent intent  = new Intent(getBaseContext(), MemoryActivity.class);
            		startActivity(intent);
                }
            })
            //if the player presses no do this
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                	//close the dialog box
                     dialog.cancel();
                }
            });
            // show it
            alertbox.show();
			
		}else if(v == findViewById(R.id.turncards)){
			//fusk
			//Button t01w=(Button)findViewById(R.id.submit);
			//submit button becomes visible
			//t01w.setVisibility(0);
			//cards are turned and turn is increased by 1
			hsdata.incTurn();
			//update the turns label
			TextView t1=(TextView)findViewById(R.id.turns);
			t1.setText("Turns: " + hsdata.getTurns());
			
			//compare the two selected cards, if the same run the if statement
			if(player.getRealCardId(player.getCardId1()) == player.getRealCardId(player.getCardId2())){
				//show a new tip
				TextView td=(TextView)findViewById(R.id.error);
				td.setText("Tip: The 2 cards match! Pick 2 new cards now.");
				//the card was the same and now they are finished, set it!
				player.setCardFinished(player.getCardId1(), true);
				player.setCardFinished(player.getCardId2(), true);
				//clear the player cards, the 2 selected cards.
				player.clearCardId();
				//set player turn to 0.
				player.resetTurn();
				
				int x=0;
				//this checks if all 24 cards are finished. 
				for(int i=1; i<25;i++){
					if(player.getCardFinished(i) == true){
						x=x+1;
					}
				}
				
				//if all was finished, run this:
				if(x>=23){
					timeFinished = 1;
					TextView t0=(TextView)findViewById(R.id.error);
					//show winner message
					t0.setText("Tip: You finished the game. Congratulations!");
					Button t01=(Button)findViewById(R.id.submit);
					//submit button becomes visible
					t01.setVisibility(0);
					//turncard button becomes invisible
					Button t02=(Button)findViewById(R.id.turncards);
					t02.setVisibility(1);
				}
				
			}else{
				if(player.getCardId1() != 0 & player.getCardId2() != 0){
					//clear players turn.
					player.resetTurn();
					//clear the 2 cards selected
					player.clearCardId();
					TextView t0=(TextView)findViewById(R.id.error);
					//show new tip message
					t0.setText("Tip: Pick 2 cards.");
					//turn all of the cards.
					if(player.getCardFinished(1) == false){
						ImageView cardid1 = (ImageView) findViewById(R.id.card1);
						cardid1.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(2) == false){
						ImageView cardid2 = (ImageView) findViewById(R.id.card2);
						cardid2.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(3) == false){
						ImageView cardid3 = (ImageView) findViewById(R.id.card3);
						cardid3.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(4) == false){
						ImageView cardid4 = (ImageView) findViewById(R.id.card4);
						cardid4.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(5) == false){
						ImageView cardid5 = (ImageView) findViewById(R.id.card5);
						cardid5.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(6) == false){
						ImageView cardid6 = (ImageView) findViewById(R.id.card6);
						cardid6.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(7) == false){
						ImageView cardid7 = (ImageView) findViewById(R.id.card7);
						cardid7.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(8) == false){
						ImageView cardid8 = (ImageView) findViewById(R.id.card8);
						cardid8.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(9) == false){
						ImageView cardid9 = (ImageView) findViewById(R.id.card9);
						cardid9.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(10) == false){
						ImageView cardid10 = (ImageView) findViewById(R.id.card10);
						cardid10.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(11) == false){
						ImageView cardid11 = (ImageView) findViewById(R.id.card11);
						cardid11.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(12) == false){
						ImageView cardid12 = (ImageView) findViewById(R.id.card12);
						cardid12.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(13) == false){
						ImageView cardid13 = (ImageView) findViewById(R.id.card13);
						cardid13.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(14) == false){
						ImageView cardid14 = (ImageView) findViewById(R.id.card14);
						cardid14.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(15) == false){
						ImageView cardid15 = (ImageView) findViewById(R.id.card15);
						cardid15.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(16) == false){
						ImageView cardid16 = (ImageView) findViewById(R.id.card16);
						cardid16.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(17) == false){
						ImageView cardid17 = (ImageView) findViewById(R.id.card17);
						cardid17.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(18) == false){
						ImageView cardid18 = (ImageView) findViewById(R.id.card18);
						cardid18.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(19) == false){
						ImageView cardid19 = (ImageView) findViewById(R.id.card19);
						cardid19.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(20) == false){
						ImageView cardid20 = (ImageView) findViewById(R.id.card20);
						cardid20.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(21) == false){
						ImageView cardid21 = (ImageView) findViewById(R.id.card21);
						cardid21.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(22) == false){
						ImageView cardid22 = (ImageView) findViewById(R.id.card22);
						cardid22.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(23) == false){
						ImageView cardid23 = (ImageView) findViewById(R.id.card23);
						cardid23.setImageResource(R.drawable.card);
					}
					if(player.getCardFinished(24) == false){
						ImageView cardid24 = (ImageView) findViewById(R.id.card24);
						cardid24.setImageResource(R.drawable.card);
					}
				}else{
					//trying to turn the cards without having 2 cards selected.
					TextView t0=(TextView)findViewById(R.id.error);
					t0.setText("Tip: You need 2 selected cards to turn.");
				}
				
			}
			//the following is repeated for the different buttons.
			//therefore I explain it in card1 only
		}else if(v == findViewById(R.id.card1)){
			//check if turns is 0 or 1, if so pick the card.
			if(player.getTurn() < 2){
				//check to see if the card is finished. if so show tip message.
				if(player.getCardFinished(1) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					//informs the player that the card is already finished.
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 1){
					//You cant selected the same card again.
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					//you picked a card.
					player.incTurn(); //increases the player turn by 1
					player.setCardId(1); // set the card to the player card slot
					ImageView image1 = (ImageView) findViewById(R.id.card1);
					//show the real image for this turned card.
					image1.setImageResource(card1.getImageName());
				}
			}else{
				//getTurns returned 2, and u already have 2 cards selected
				TextView t2=(TextView)findViewById(R.id.error);
				//show new tip message
				t2.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card2)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(2) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 2){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(2);
					ImageView image2 = (ImageView) findViewById(R.id.card2);
					image2.setImageResource(card2.getImageName());
				}
			}else{
				TextView t4=(TextView)findViewById(R.id.error);
				t4.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card3)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(3) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 3){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(3);
					ImageView image3 = (ImageView) findViewById(R.id.card3);
					image3.setImageResource(card3.getImageName());
				}
			}else{
				TextView t6=(TextView)findViewById(R.id.error);
				t6.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card4)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(4) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 4){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(4);
					ImageView image4 = (ImageView) findViewById(R.id.card4);
					image4.setImageResource(card4.getImageName());
				}
			}else{
				TextView t8=(TextView)findViewById(R.id.error);
				t8.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card5)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(5) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 5){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(5);
					ImageView image5 = (ImageView) findViewById(R.id.card5);
					image5.setImageResource(card5.getImageName());
				}
			}else{
				TextView t10=(TextView)findViewById(R.id.error);
				t10.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card6)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(6) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 6){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(6);
					ImageView image6 = (ImageView) findViewById(R.id.card6);
					image6.setImageResource(card6.getImageName());
				}
			}else{
				TextView t12=(TextView)findViewById(R.id.error);
				t12.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card7)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(7) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 7){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(7);
					ImageView image7 = (ImageView) findViewById(R.id.card7);
					image7.setImageResource(card7.getImageName());
				}
			}else{
				TextView t14=(TextView)findViewById(R.id.error);
				t14.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card8)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(8) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 8){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(8);
					ImageView image8 = (ImageView) findViewById(R.id.card8);
					image8.setImageResource(card8.getImageName());
				}
			}else{
				TextView t16=(TextView)findViewById(R.id.error);
				t16.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card9)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(9) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 9){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(9);
					ImageView image9 = (ImageView) findViewById(R.id.card9);
					image9.setImageResource(card9.getImageName());
				}
			}else{
				TextView t18=(TextView)findViewById(R.id.error);
				t18.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card10)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(10) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 10){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(10);
					ImageView image10 = (ImageView) findViewById(R.id.card10);
					image10.setImageResource(card10.getImageName());
				}
			}else{
				TextView t20=(TextView)findViewById(R.id.error);
				t20.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card11)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(11) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 11){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(11);
					ImageView image11 = (ImageView) findViewById(R.id.card11);
					image11.setImageResource(card11.getImageName());
				}
			}else{
				TextView t22=(TextView)findViewById(R.id.error);
				t22.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card12)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(12) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 12){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(12);
					ImageView image12 = (ImageView) findViewById(R.id.card12);
					image12.setImageResource(card12.getImageName());
				}
			}else{
				TextView t24=(TextView)findViewById(R.id.error);
				t24.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card13)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(13) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 13){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(13);
					ImageView image13 = (ImageView) findViewById(R.id.card13);
					image13.setImageResource(card13.getImageName());
				}
			}else{
				TextView t26=(TextView)findViewById(R.id.error);
				t26.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card14)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(14) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 14){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(14);
					ImageView image14 = (ImageView) findViewById(R.id.card14);
					image14.setImageResource(card14.getImageName());
				}
			}else{
				TextView t28=(TextView)findViewById(R.id.error);
				t28.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card15)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(15) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 15){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(15);
					ImageView image15 = (ImageView) findViewById(R.id.card15);
					image15.setImageResource(card15.getImageName());
				}
			}else{
				TextView t30=(TextView)findViewById(R.id.error);
				t30.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card16)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(16) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 16){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(16);
					ImageView image16 = (ImageView) findViewById(R.id.card16);
					image16.setImageResource(card16.getImageName());
				}
			}else{
				TextView t32=(TextView)findViewById(R.id.error);
				t32.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card17)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(17) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 17){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(17);
					ImageView image17 = (ImageView) findViewById(R.id.card17);
					image17.setImageResource(card17.getImageName());
				}
			}else{
				TextView t34=(TextView)findViewById(R.id.error);
				t34.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card18)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(18) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 18){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(18);
					ImageView image18 = (ImageView) findViewById(R.id.card18);
					image18.setImageResource(card18.getImageName());
				}
			}else{
				TextView t36=(TextView)findViewById(R.id.error);
				t36.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card19)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(19) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 19){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(19);
					ImageView image19 = (ImageView) findViewById(R.id.card19);
					image19.setImageResource(card19.getImageName());
				}
			}else{
				TextView t38=(TextView)findViewById(R.id.error);
				t38.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card20)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(20) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 20){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(20);
					ImageView image20 = (ImageView) findViewById(R.id.card20);
					image20.setImageResource(card20.getImageName());
				}
			}else{
				TextView t40=(TextView)findViewById(R.id.error);
				t40.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card21)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(21) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 21){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(21);
					ImageView image21 = (ImageView) findViewById(R.id.card21);
					image21.setImageResource(card21.getImageName());
				}
			}else{
				TextView t42=(TextView)findViewById(R.id.error);
				t42.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card22)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(22) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 22){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(22);
					ImageView image22 = (ImageView) findViewById(R.id.card22);
					image22.setImageResource(card22.getImageName());
				}
			}else{
				TextView t44=(TextView)findViewById(R.id.error);
				t44.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card23)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(23) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 23){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(23);
					ImageView image23 = (ImageView) findViewById(R.id.card23);
					image23.setImageResource(card23.getImageName());
				}
			}else{
				TextView t46=(TextView)findViewById(R.id.error);
				t46.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}else if(v == findViewById(R.id.card24)){
			if(player.getTurn() < 2){
				if(player.getCardFinished(24) == true){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select a finished card.");
				}else if(player.getCardId1() == 24){
					TextView t2=(TextView)findViewById(R.id.error);
					t2.setText("Tip: You can't select the same card twice.");
				}else{
					player.incTurn();
					player.setCardId(24);
					ImageView image24 = (ImageView) findViewById(R.id.card24);
					image24.setImageResource(card24.getImageName());
				}
			}else{
				TextView t48=(TextView)findViewById(R.id.error);
				t48.setText("Tip: You already have 2 selected. Turn Cards!");
			}
		}
		
	}
}

